﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InHD.model;
using InHD.commands;
using System.Windows.Input;
using System.Collections.ObjectModel;

namespace InHD.viewmodels
{
    class StaffListViewModel:WorkspaceViewModel
    {

        #region Value Property
        private ObservableCollection<Staff> _staffRowCollection;
        private int _rowIndex = -1;
        public string commandExcute = string.Empty;
        private Staff _staff;
        #endregion

        #region Constructor
        public StaffListViewModel(ObservableCollection<Staff> listStaff)
        {
            StaffRowCollection = listStaff;
        }
        #endregion

        #region Presentation Property
        public ObservableCollection<Staff> StaffRowCollection
        {
            get
            {
                return _staffRowCollection;
            }
            set
            {
                if (_staffRowCollection != value)
                {
                    _staffRowCollection = value;
                    OnPropertyChanged("StaffRowCollection");
                }
            }
        }

        public int RowIndex
        {
            get
            {
                return this._rowIndex;
            }
            set
            {
                this._rowIndex = value;
                OnPropertyChanged("RowIndex");
            }
        }

        public Staff SelectedStaff
        {
            get { return this._staff; }
            set
            {
                if (value != null)
                {
                    this._staff = value;
                }
            }
        }
        #endregion

        #region Command 
        private RelayCommand _viewStaffCommand;
        public ICommand ViewStaffCommand
        {
            get
            {
                if (_viewStaffCommand == null)
                {
                    _viewStaffCommand = new RelayCommand(
                        (param) => this.ViewStaff(), (param) => this.CanView);
                }
                return _viewStaffCommand;
            }
        }

        private RelayCommand _addNewStaffCommand;
        public ICommand AddNewStaffCommand
        {
            get
            {
                if (_addNewStaffCommand == null)
                {
                    _addNewStaffCommand = new RelayCommand(
                        (param) => this.AddNewStaff());
                }
                return _addNewStaffCommand;
            }
        }
        #endregion

        #region Command Method
        void ViewStaff()
        {
            commandExcute = "View";
            OnRequestClose();
        }

        void AddNewStaff()
        {
            commandExcute = "Add";
            OnRequestClose();
        }
        #endregion

        public bool CanView { get { return (this.SelectedStaff == null) ? false : true;} }
    }
}
